﻿using System;
using System.Data;
using System.Data.OracleClient;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class MobileLogin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void loginIn_Click(object sender, EventArgs e)
    {
        string sqlStr = "SELECT count(1) FROM USER_INFO " +
                             "WHERE UPPER(ULOGIN)=UPPER(:USER_LOGIN) AND UPASS=:USER_PASS " +
                               "AND IFValid='Y'";
        OracleParameter[] _param ={
			    new OracleParameter(":USER_LOGIN",OracleType.VarChar),
                new OracleParameter(":USER_PASS",OracleType.VarChar)
			};
        _param[0].Value = loginnameTxT.Text.Trim();
        _param[1].Value = passwordTxT.Text.Trim();
        int count = Int32.Parse(OracleHelper.ExecuteScalar(sqlStr, CommandType.Text, _param).ToString());
        Session["LoginUser"] = count > 0 ? loginnameTxT.Text.Trim() : null;
        if (Session["LoginUser"] == null)
        {
            LoginFail();
        }
        else
        {
            LoginSuccess();
        }
        passwordTxT.Text = String.Empty;
    }

    private void LoginSuccess()
    {
        if (BasicPage.CheckAgent())
        {
            log4net.LogManager.GetLogger(GetType()).Info("{ClientIP:'" + BasicPage.GetClientIP() + "',Msg:'"
                + Session["LoginUser"].ToString() + " login by mobile.'}");
            Response.Redirect("~/Show/MobileIndex.aspx");
        }
        else
        {            
            Response.Redirect("~/Show/Index.aspx");
        }
    }

    private void LoginFail()
    {
        msg.Text = "用户名或者密码有误，请重试！";
        passwordTxT.Focus();
    }
}
